package org.gdstash.combobox;

import com.jidesoft.combobox.FilterableComboBoxModel;
import com.jidesoft.grid.ComboBoxShrinkSearchableSupport;
import com.jidesoft.swing.AutoCompletionComboBox;
import com.jidesoft.swing.ComboBoxSearchable;
import com.jidesoft.swing.SearchableUtils;
import com.jidesoft.swing.event.SearchableEvent;
import org.gdstash.ui.util.WideComboBox;
import org.jdesktop.swingx.search.SearchFactory;

import javax.swing.*;
import java.awt.*;

public class ComboBoxWithSearch {
    public static void main(String[] args) {
        JFrame frame = new JFrame("ComboBox with Search");

        JComboBox<String> comboBox = new WideComboBox<>();
        // 填充JComboBox以模拟较长列表
        for (int i = 0; i < 100; i++) {
            comboBox.addItem("Item " + i);
        }
        comboBox.setEditable(true);
        ComboBoxSearchable searchable = new ComboBoxSearchable(comboBox) {
            @Override
            protected boolean compare(String text, String searchingText) {
                boolean contains = text.toLowerCase().contains(searchingText.toLowerCase());
                return contains;
            }
        };


        // 将JScrollPane添加到JFrame的内容面板
        frame.getContentPane().add(comboBox, BorderLayout.CENTER);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}